package managedbeans;

import entities.Forumblocks;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import langresources.ResourcesController;
import utils.dataaccess.DBInterface;



@ManagedBean(name = "newBlockBean")
@SessionScoped
public class NewBlockBean  extends GenericForumBean implements Serializable{

    private Forumblocks newBlock;
    private String title;
    private String text;
    
    public NewBlockBean() {
        newBlock = new Forumblocks();
    }
    
    public String createBlock(){
            newBlock.setId(generateID());
            newBlock.setName(title);
            newBlock.setPostsnumber(0);
            newBlock.setThreadnumber(0);
            DBInterface.save(newBlock);
            showMessage(ResourcesController.extractResource("MESSAGE.INFO"), ResourcesController.extractResource("BLOCK_CREATED"));
            return "BLOCK_CREATED";
    }

    // GETTERS-SETTERS

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }  
}
